#ifndef __BUOLA_SCENE_CNODE_H__
#define __BUOLA_SCENE_CNODE_H__

#include <buola/scene.h>

namespace buola { namespace scene {

class CNode : public UShared
{
protected:
    CNode();
    virtual ~CNode();

public:
    const std::string &GetName() const  {   return mName;   }
    PNode GetParent()              {   return mParent; }

    void AddChild(PNode pNode);

    const mat::CVec3d &GetTranslation()           {   return mTranslation;    }
    const mat::CQuat &GetRotation()            {   return mRotation;       }
    const mat::CVec3d &GetScale()                 {   return mScale;          }

    const mat::CMat4d &GetLocalTransform()
    {
        if(!(mFlags&FLAG_VALID_LOCALTRANSFORM))
            CalcLocalTransform();
        return mLocalTransform;
    }

    void SetPose(const mat::CVec3d &pTranslate={0,0,0},
                 const mat::CQuat &pOrientation=mat::CQuat(),
                 const mat::CVec3d &pScale={1,1,1});
    void SetTranslation(const mat::CVec3d &pTranslation={0,0,0});
    void SetRotation(const mat::CQuat &pRotation=mat::CQuat());
    void SetScale(const mat::CVec3d &pScale={1,1,1});

private:
    void CalcLocalTransform();

private:
    CNode *mParent;
    std::vector<PNode> mChildren;
    const std::string mName;

    mat::CVec3d mTranslation;
    mat::CQuat mRotation;
    mat::CVec3d mScale;

    mat::CMat4d mLocalTransform;
    mat::CMat4d mWorldTransform;

    EFlags mFlags;
};

/*namespace scene*/ } /*namespace buola*/ }

#endif
